<template>
  <div>
    <div class="history">
      <div class="history_top">
        <h2>历史记录</h2>
        <van-icon name="delete-o" @click="clearHistory" />
      </div>
      <div class="history_down">
        <van-tag
          v-for="(item, index) in historyKeywordList"
          :key="index"
          plain
          type="default"
          @click="tagClick(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>
    <div class="history">
      <div class="history_top">
        <h2>热门搜索</h2>
      </div>
      <div class="history_down">
        <van-tag
          v-for="(item, index) in hotKeywordList"
          :key="index"
          plain
          :type="item.is_hot == 1 ? 'danger' : 'default'"
          @click="tagClick(item.keyword)"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import {ClearHistoryApi} from '@/request/api'
export default {
  props: ["historyKeywordList", "hotKeywordList"],
  data() {
    return {};
  },
  methods: {
    // 点击标签,然后跳转到产品区块,并且替换keyword
    tagClick(arg){
      this.$emit("listClickFn", 2, arg)
    },
    // 清除历史记录
    clearHistory(){
      ClearHistoryApi().then(res=>{
        if(res.errno===0){
          this.$emit("getPopupData")
        }
      })
    }
  }
};
</script>
 
<style lang = "less" scoped>
.history {
  background: #fff;
  padding: 10px;
  margin-bottom: 20px;

  .history_top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    h2 {
      font-size: 18px;
    }
  }

  .history_down {
    .van-tag {
      margin-right: 10px;
      margin-bottom: 10px;
    }
  }
}
</style>